/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.geftu.util;

import br.com.geftu.HibernateUtil.HibernateUtil;
import br.com.geftu.model.Desenvolvedor;
import java.awt.HeadlessException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Nei
 */
public class ValidaAcesso {

    List<Desenvolvedor> lista_desenvolvedor = new ArrayList();

    public Desenvolvedor validar(String user, String pass) {
        Desenvolvedor desenvolvedor = new Desenvolvedor();
        try {
            Session sessao = HibernateUtil.getSessionFactory().openSession();
            Criteria criteria = sessao.createCriteria(Desenvolvedor.class);
            desenvolvedor = (Desenvolvedor) criteria
                    .add(Restrictions.ilike("login", user, MatchMode.EXACT))
                    .add(Restrictions.like("senha", pass, MatchMode.EXACT))
                    .uniqueResult();
            sessao.close();

        } catch (HeadlessException | HibernateException e) {
            JOptionPane.showMessageDialog(null, e.getCause());
        }
        return desenvolvedor;

    }

}
